// pages/myOrg/myOrg.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    req:false,
    pageEnd: false,
    param: {
      pageNumber: 1,
      pageSize: 10
    },
    list: []
  },

  list: function (append) {
    var that = this;
    var param = that.data.param
    app.req({
      url: 'orgmini/org/newGetOrgList',
      data: param,
      success: function (res) {
        if (200 == res.code) {
          var list = res.data.rows;
          if (!list || list.length < param.pageSize) {
            that.toggle("pageEnd", true);
          }
          that.toggle("list", append ? that.data.list.concat(list) : list);
          that.toggle("req", true);
        }
      }
    });
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  toPage(e) {
    var dataset = e.currentTarget.dataset;
    var url = dataset.turn
    if(dataset.id){
      url = url+'?id='+dataset.id
    }
    wx.navigateTo({
      url: url
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    app.getUserInfo(function (userInfo) {
      that.toggle("req", false);
      that.toggle("param.uid", userInfo.id);
      that.list()
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    var that = this;
    app.getUserInfo(function (userInfo) {
      that.toggle("req", false);
      that.toggle("param.pageNumber", 1);
      that.toggle("pageEnd", false);
      that.list();
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (!that.data.pageEnd) {
      that.toggle("param.pageNumber", that.data.param.pageNumber + 1);
      that.list(true);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})